from vuer import Vuer, VuerSession
from vuer.schemas import Hands, MotionControllers
from asyncio import sleep

app = Vuer(host='0.0.0.0', cert="cert.pem", key="key.pem", queries=dict(grid=False), queue_len=3)

@app.add_handler("HAND_MOVE")
async def handler(event, session):
    '''
    该事件内容是空的
    '''
    print(f"Movement Event: key-{event.key}", event.value)

@app.add_handler("CONTROLLER_MOVE")
async def handler(event, session):
    '''
    该事件内容是手柄的位姿
    '''
    print(f"------Movement Event: key-{event.key}", event.value)

@app.spawn(start=True)
async def main(session: VuerSession):
    # Important: You need to set the `stream` option to `True` to start
    # streaming the hand movement.

    session.upsert @ MotionControllers(stream=True, key="motion-controller")
    session.upsert(
        Hands(
            stream=True,
            key="hands",
            # hideLeft=False,       # hides the hand, but still streams the data.
            # hideRight=False,      # hides the hand, but still streams the data.
            # disableLeft=False,    # disables the left data stream, also hides the hand.
            # disableRight=False,   # disables the right data stream, also hides the hand.
        ),
        to="bgChildren",
    )

    while True:
        await sleep(1)